﻿using ServerBase.Client;
using ServerBase.Config;
using ServerBase.Other;
using ServerBase.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UtilLib;
using UtilPublic.ApiDispatcher;
using UtilPublic.Serialization;
using static UtilPublic.Serialization.Jsh;

namespace ToolGame
{
    /// <summary>
    /// PagePlayer.xaml 的交互逻辑
    /// </summary>
    public partial class PagePlayer : Page
    {
        public PagePlayer()
        {
            InitializeComponent();

            ComboBoxPlayerEditMode.ComboBox.ItemsSource = Enum.GetValues(typeof(EGtPlayerEdit));
            ComboBoxPlayerEditMode.ComboBox.SelectedIndex = 0;

            ComboBoxPlayerEditFamilyName.ComboBox.ItemsSource = Conf.ConfToolFamily.Keys;
            ComboBoxPlayerEditFamilyName.ComboBox.SelectedIndex = 0;

            MainWindow.绑定控制器(this);
        }

        private void Button_Click_Public(object sender, RoutedEventArgs e) { App.WdMain.Button_Click_Public(sender, e); }


        #region 返回
        [ApiDpPubIA1((int)EGtAction.玩家数据查询基本信息)]
        public void 玩家数据查询基本信息(G2B_Gt_Action Rsp)
        {
            var GtArgs = Jsh.Jobj<CLS_Info_Base>(Rsp.GtArgs);

            BasePropMgr.GetFieldsDescList(GtArgs, out var ListDatas);
            DataGridPlayerInfoBase.BindingObj(ListDatas);
        }
        [ApiDpPubIA1((int)EGtAction.玩家数据查询杂项信息)]
        public void 玩家数据查询杂项信息(G2B_Gt_Action Rsp)
        {
            var GtArgs = Jsh.Jobj<CLS_Info_Misc>(Rsp.GtArgs);

            BasePropMgr.GetFieldsDescList(GtArgs, out var ListDatas);
            DataGridPlayerInfoMisc.BindingObj(ListDatas);
            DataGridPlayerInfoMiscFlagInt.BindingDictObj(GtArgs.DictFlagInt.ToDictionary(it => (EFlagInt)it.Key, it => it.Value));
            DataGridPlayerInfoMiscFlagBool.BindingDictObj(GtArgs.DictFlagBool.ToDictionary(it => (EFlagBool)it.Key, it => it.Value));
        }
        [ApiDpPubIA1((int)EGtAction.玩家数据查询账号信息)]
        public void 玩家数据查询账号信息(G2B_Gt_Action Rsp)
        {
            var GtArgs = Jsh.Jobj<CLS_GtPlayerInfoUser>(Rsp.GtArgs);

            BasePropMgr.GetFieldsDescList(GtArgs, out var ListDatas);
            DataGridPlayerInfoUser.BindingObj(ListDatas);
        }
        [ApiDpPubIA1((int)EGtAction.玩家数据查询游戏信息)]
        public void 玩家数据查询游戏信息(G2B_Gt_Action Rsp)
        {
            var GtArgs = Jsh.Jobj<CLS_Info_Game>(Rsp.GtArgs);

            BasePropMgr.GetFieldsDescList(GtArgs, out var ListDatas);
            DataGridPlayerInfoGame.BindingObj(ListDatas);
        }
        [ApiDpPubIA1((int)EGtAction.玩家数据查询原始数据)]
        public void 玩家数据查询原始数据(G2B_Gt_Action Rsp)
        {
            TextBoxPlayerInfoDataGet.Text = Rsp.GtArgs;
        }
        #endregion

        
        #region 按钮
        [ApiDpPubSA0("ButtonPlayerInfoBase")]
        public void OButtonPlayerInfoBase()
        {
            var Req = App.GetReq(EGtAction.玩家数据查询基本信息, TextBoxPlayerPuid.Text);
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerInfoMisc")]
        public void OButtonPlayerInfoMisc()
        {
            var Req = App.GetReq(EGtAction.玩家数据查询杂项信息, TextBoxPlayerPuid.Text);
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerInfoUser")]
        public void OButtonPlayerInfoUser()
        {
            var Req = App.GetReq(EGtAction.玩家数据查询账号信息, TextBoxPlayerPuid.Text);
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerInfoGame")]
        public void OButtonPlayerInfoGame()
        {
            var Req = App.GetReq(EGtAction.玩家数据查询游戏信息, TextBoxPlayerPuid.Text);
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerInfoDataGet")]
        public void OButtonPlayerInfoDataGet()
        {
            var Req = App.GetReq(EGtAction.玩家数据查询原始数据, TextBoxPlayerPuid.Text);
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerInfoDataShow")]
        public void OButtonPlayerInfoDataShow()
        {
            TreeViewPlayerInfoDataShow.BindJson(TextBoxPlayerInfoDataGet.Text);
        }
        [ApiDpPubSA0("ButtonPlayerEdit")]
        public void OButtonPlayerEdit()
        {
            if (TextBoxPlayerPuid.Text.IsNullOrEmpty())
            {
                App.DebugError("玩家唯一ID或者昵称 不能为空！"); return;
            }
            var GtArgs = new CLS_GtPlayerEdit()
            {
                Puid = TextBoxPlayerPuid.Text,
                EditMode = ComboBoxPlayerEditMode.ComboBox.SelectedItem.ToString(),
            };
            if (GtArgs.EditMode.IsNullOrEmpty())
            {
                App.DebugError("错误的修改方式！"); return;
            }
            GtArgs.EditArg = TextBoxPlayerEditArg.TextboxText;

            var Req = App.GetReq(EGtAction.玩家数据修改, Jsh.Jstr(GtArgs));
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerEditItem")]
        public void OButtonPlayerEditItem()
        {
            if (TextBoxPlayerPuid.Text.IsNullOrEmpty())
            {
                App.DebugError("玩家唯一ID或者昵称 不能为空！"); return;
            }
            var GtArgs = new CLS_GtPlayerEdit()
            {
                Puid = TextBoxPlayerPuid.Text,
                EditMode = EGtPlayerEdit.获取道具.ToString(),
            };
            var liststr = ComboBoxPlayerEditItemConfigId.ComboBoxText.ToListString("|");
            GtArgs.EditArg = $"{liststr[0]};{TextBoxPlayerEditItemCount.TextboxText}";

            var Req = App.GetReq(EGtAction.玩家数据修改, Jsh.Jstr(GtArgs));
            App.ClientNetSingle.Send(Req);
        }
        [ApiDpPubSA0("ButtonPlayerEditFamily")]
        public void OButtonPlayerEditFamily()
        {
            if (TextBoxPlayerPuid.Text.IsNullOrEmpty())
            {
                App.DebugError("玩家唯一ID或者昵称 不能为空！"); return;
            }
            var GtArgs = new CLS_GtPlayerEdit()
            {
                Puid = TextBoxPlayerPuid.Text,
                EditMode = EGtPlayerEdit.变更门派.ToString(),
            };
            GtArgs.EditArg = $"{ComboBoxPlayerEditFamilyName.ComboBoxText}";

            var Req = App.GetReq(EGtAction.玩家数据修改, Jsh.Jstr(GtArgs));
            App.ClientNetSingle.Send(Req);
        }

        #endregion


    }
}
